﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using YArchitech.BIM;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YArchitech.DataModel
{
	public class SpaceParameterOperate
	{
		public static void CreatSpaceShareParam(UIApplication uiApp)
		{
			List<string> list = new List<string>();
			list.Add("基础房间ID");
			list.Add("关键字空间类型ID");
            YJKRevitTools.SetInstanceParameter(uiApp, SpaceParameterOperate.spaceShareParaPath, "墙体附加数据", list, BuiltInCategory.OST_MEPSpaces, false, BuiltInParameterGroup.INVALID);
		}

		public static List<string> GetAllLoadParaName()
		{
			List<string> list = new List<string>();
			XElement xelement = XElement.Load(SpaceParameterOperate.spaceLoadPath);
			foreach (XElement xelement2 in xelement.Elements())
			{
				list.Add(xelement2.Value);
			}
			return list;
		}

		public static void CreatLoadParaShareInfo(UIApplication uiApp)
		{
			List<string> allLoadParaName = SpaceParameterOperate.GetAllLoadParaName();
			YJKRevitTools.SetInstanceParameter(uiApp, SpaceParameterOperate.loadShareParaPath, "盈建科空间附加数据", allLoadParaName, BuiltInCategory.OST_MEPSpaces, true);
		}

		public static IList<RoomKeyToSpace> GetAllKeysToSpace()
		{
			IList<RoomKeyToSpace> list = new List<RoomKeyToSpace>();
			try
			{
				XElement xelement = XElement.Load(SpaceParameterOperate.pathSpaceKey);
				foreach (XElement xelement2 in xelement.Elements())
				{
					list.Add(new RoomKeyToSpace
					{
						KeyId = xelement2.Attribute("KID").Value,
						RoomKey = xelement2.Attribute("RoomKey").Value,
						RoomUseName = xelement2.Attribute("RoomUseName").Value,
						RoomUseId = Convert.ToInt32(xelement2.Attribute("RoomUseId").Value),
						Opetation = xelement2.Attribute("Operation").Value,
                        //Opetation = "无操作"
					});
				}
			}
			catch (Exception)
			{
				throw;
			}
			return list;
		}

		public static IList<SpaceParameterInfo> GetAllSpaceInfo()
		{
			IList<SpaceParameterInfo> list = new List<SpaceParameterInfo>();
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("select * from RoomUse", new object[0]);
			DataTable dataTable = DataAccessOperate.GetDataTable(sqlStr);
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new SpaceParameterInfo
				{
					RoomId = ((dataRow["Id"] is DBNull) ? 0 : Convert.ToInt32(dataRow["Id"])),
					RoomTypeId = ((dataRow["RTId"] is DBNull) ? 0 : Convert.ToInt32(dataRow["RTId"])),
					RoomName = ((dataRow["Name"] is DBNull) ? "" : Convert.ToString(dataRow["Name"])),
					Operation = "无操作"
				});
			}
			foreach (SpaceParameterInfo spaceParameterInfo in list)
			{
				sqlStr = string.Format("select * from RoomType where Id={0}", spaceParameterInfo.RoomTypeId);
				dataTable = DataAccessOperate.GetDataTable(sqlStr);
				foreach (object obj2 in dataTable.Rows)
				{
					DataRow dataRow2 = (DataRow)obj2;
					spaceParameterInfo.RoomTypeName = ((dataRow2["Name"] is DBNull) ? "" : Convert.ToString(dataRow2["Name"]));
				}
				sqlStr = string.Format("select * from RULoadParam where RUId={0} ", spaceParameterInfo.RoomId);
				dataTable = DataAccessOperate.GetDataTable(sqlStr);
				DataRow dataRow3 = dataTable.Rows[0];
				spaceParameterInfo.Param = new List<SpacePara>();
				SpacePara spacePara = new SpacePara();
				spacePara.Key = "电动设备功率(W/m2)";
				spacePara.Value = ((dataRow3["DianDongGL"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianDongGL"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电动设备时间表";
				spacePara.Value = ((dataRow3["DianDongSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["DianDongSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电动设备同时使用系数";
				spacePara.Value = ((dataRow3["DianDongTSSYXS"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianDongTSSYXS"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电热设备功率(W/m2)";
				spacePara.Value = ((dataRow3["DianReGL"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianReGL"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电热设备时间表";
				spacePara.Value = ((dataRow3["DianReSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["DianReSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电热设备同时使用系数";
				spacePara.Value = ((dataRow3["DianReTSSYXS"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianReTSSYXS"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电子设备功率(W/m2)";
				spacePara.Value = ((dataRow3["DianZiGL"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianZiGL"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电子设备时间表";
				spacePara.Value = ((dataRow3["DianZiSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["DianZiSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "电子设备同时使用系数";
				spacePara.Value = ((dataRow3["DianZiTSSYXS"] is DBNull) ? "0" : Convert.ToString(dataRow3["DianZiTSSYXS"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "冬季采暖设计相对湿度";
				spacePara.Value = ((dataRow3["DongJiCNSJXDSD"] is DBNull) ? "0" : Convert.ToString(dataRow3["DongJiCNSJXDSD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "冬季采暖设计温度";
				spacePara.Value = ((dataRow3["DongJiCNSNSJWD"] is DBNull) ? "0" : Convert.ToString(dataRow3["DongJiCNSNSJWD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "冬季空调设计温度";
				spacePara.Value = ((dataRow3["DongJiSNSJWD"] is DBNull) ? "0" : Convert.ToString(dataRow3["DongJiSNSJWD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "冬季空调设计相对湿度";
				spacePara.Value = ((dataRow3["DongJiSNSJXDSD"] is DBNull) ? "0" : Convert.ToString(dataRow3["DongJiSNSJXDSD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "劳动强度(enum)";
				spacePara.Value = ((dataRow3["LaoDongQD"] is DBNull) ? "0" : Convert.ToString(dataRow3["LaoDongQD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "其他冷指标";
				spacePara.Value = ((dataRow3["QiTaLZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["QiTaLZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "其他热指标(W/m^2)";
				spacePara.Value = ((dataRow3["QiTaRZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["QiTaRZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "人员密度";
				spacePara.Value = ((dataRow3["RenYuanMD"] is DBNull) ? "0" : Convert.ToString(dataRow3["RenYuanMD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "人员总数";
				spacePara.Value = ((dataRow3["RenYuanZS"] is DBNull) ? "0" : Convert.ToString(dataRow3["RenYuanZS"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "人员冷指标";
				spacePara.Value = ((dataRow3["RenYuanLZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["RenYuanLZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "人员热指标";
				spacePara.Value = ((dataRow3["RenYuanRZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["RenYuanRZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "人员时间表";
				spacePara.Value = ((dataRow3["RenYuanSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["RenYuanSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "设备标准";
				spacePara.Value = ((dataRow3["SheBeiBZ"] is DBNull) ? "0" : Convert.ToString(dataRow3["SheBeiBZ"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "室内允许最大风速(m/s)";
				spacePara.Value = ((dataRow3["ShiNeiZDFS"] is DBNull) ? "0" : Convert.ToString(dataRow3["ShiNeiZDFS"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "维护冷指标";
				spacePara.Value = ((dataRow3["WeiHuLZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["WeiHuLZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "维护热指标";
				spacePara.Value = ((dataRow3["WeiHuRZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["WeiHuRZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "夏季空调设计温度";
				spacePara.Value = ((dataRow3["XiaJiSNSJWD"] is DBNull) ? "0" : Convert.ToString(dataRow3["XiaJiSNSJWD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "夏季空调设计相对湿度";
				spacePara.Value = ((dataRow3["XiaJiSNSJXDSD"] is DBNull) ? "0" : Convert.ToString(dataRow3["XiaJiSNSJXDSD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "新风量";
				spacePara.Value = ((dataRow3["XinFengL"] is DBNull) ? "0" : Convert.ToString(dataRow3["XinFengL"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "新风冷指标";
				spacePara.Value = ((dataRow3["XinFengLZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["XinFengLZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "新风热指标";
				spacePara.Value = ((dataRow3["XinFengRZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["XinFengRZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "新风时间表";
				spacePara.Value = ((dataRow3["XinFengSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["XinFengSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "用水量标准";
				spacePara.Value = ((dataRow3["YongShuiBZ"] is DBNull) ? "0" : Convert.ToString(dataRow3["YongShuiBZ"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "允许采暖设计温度波动";
				spacePara.Value = ((dataRow3["YunXuDJSJWDBD"] is DBNull) ? "0" : Convert.ToString(dataRow3["YunXuDJSJWDBD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "允许采暖设计相对湿度波动";
				spacePara.Value = ((dataRow3["YunXuDJSJXDSDBD"] is DBNull) ? "0" : Convert.ToString(dataRow3["YunXuDJSJXDSDBD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "允许设计温度波动";
				spacePara.Value = ((dataRow3["YunXuSJWDBD"] is DBNull) ? "0" : Convert.ToString(dataRow3["YunXuSJWDBD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "允许设计相对湿度波动";
				spacePara.Value = ((dataRow3["YunXuSJXDSDBD"] is DBNull) ? "0" : Convert.ToString(dataRow3["YunXuSJXDSDBD"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "噪音";
				spacePara.Value = ((dataRow3["ZaoYin"] is DBNull) ? "0" : Convert.ToString(dataRow3["ZaoYin"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "照度";
				spacePara.Value = ((dataRow3["ZhaoDu"] is DBNull) ? "0" : Convert.ToString(dataRow3["ZhaoDu"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "照明标准";
				spacePara.Value = ((dataRow3["ZhaoMingBZ"] is DBNull) ? "0" : Convert.ToString(dataRow3["ZhaoMingBZ"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "照明时间表";
				spacePara.Value = ((dataRow3["ZhaoMingSJB"] is DBNull) ? "" : Convert.ToString(dataRow3["ZhaoMingSJB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "总冷指标";
				spacePara.Value = ((dataRow3["ZongLengZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["ZongLengZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "总热指标";
				spacePara.Value = ((dataRow3["ZongReZB"] is DBNull) ? "0" : Convert.ToString(dataRow3["ZongReZB"]));
				spaceParameterInfo.Param.Add(spacePara);
				spacePara = new SpacePara();
				spacePara.Key = "ID";
				spacePara.Value = ((dataRow3["Id"] is DBNull) ? "0" : Convert.ToString(dataRow3["Id"]));
				spaceParameterInfo.Param.Add(spacePara);
			}
			return list;
		}

		public static bool DeleteSpaceParameterByRoomUse(int roomUseId)
		{
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("delete * from RULoadParam where RUId={0} ", roomUseId);
			if (!DataAccessOperate.Query(sqlStr))
			{
				return false;
			}
			sqlStr = string.Format("delete * from RoomUse where Id={0}", roomUseId);
			return DataAccessOperate.Query(sqlStr);
		}

		public static bool UpdateSpaceParameterInfo(SpaceParameterInfo spi)
		{
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("update RoomUse set [RTId]={0},[Name]={1} where Id={2};", spi.RoomTypeId, "'" + spi.RoomName + "'", spi.RoomId);
			if (!DataAccessOperate.Query(sqlStr))
			{
				return false;
			}
			SpaceLoadParameter spaceLoadParameter = SpaceParameterOperate.TranformSpaceInfo(spi);
			string text = "update RULoadParam set [RUId]={0},[DongJiSNSJWD]={1},[DongJiSNSJXDSD]={2},[XiaJiSNSJWD]={3},[XiaJiSNSJXDSD]={4},";
			text += "[RenYuanMD]={5},[ZhaoMingBZ]={6},[SheBeiBZ]={7},[XinFengL]={8},[ZaoYin]={9},[ZongLengZB]={10},[ZongReZB]={11},[WeiHuLZB]={12},[RenYuanLZB]={13},[XinFengLZB]={14},[QiTaLZB]={15},[WeiHuRZB]={16},";
			text += "[RenYuanRZB]={17},[XinFengRZB]={18},[LaoDongQD]={19},[ShiNeiZDFS]={20},[QiTaRZB]={21},[XinFengSJB]={22},[RenYuanSJB]={23},[ZhaoMingSJB]={24},[DianDongSJB]={25},[DianReSJB]={26},[DianZiSJB]={27},";
			text += "[DianDongGL]={28},[DianReGL]={29},[DianZiGL]={30},[RenYuanZS]={31},[YongShuiBZ]={32},[ZhaoDu]={33},[DianDongTSSYXS]={34},[DianReTSSYXS]={35},[DianZiTSSYXS]={36},[YunXuSJWDBD]={37},[YunXuDJSJWDBD]={38},";
			text += "[YunXuSJXDSDBD]={39},[YunXuDJSJXDSDBD]={40},[DongJiCNSNSJWD]={41},[DongJiCNSJXDSD]={42},[Version]={43} where Id={44}";
			sqlStr = string.Format(text, new object[]
			{
				spaceLoadParameter.RoomUseId,
				spaceLoadParameter.DongJiSNSJWD,
				spaceLoadParameter.DongJiSNSJXDSD,
				spaceLoadParameter.XiaJiSNSJWD,
				spaceLoadParameter.XiaJiSNSJXDSD,
				spaceLoadParameter.RenYuanMD,
				spaceLoadParameter.ZhaoMingBZ,
				spaceLoadParameter.SheBeiBZ,
				spaceLoadParameter.XinFengL,
				spaceLoadParameter.ZaoYin,
				spaceLoadParameter.ZongLengZB,
				spaceLoadParameter.ZongReZB,
				spaceLoadParameter.WeiHuLZB,
				spaceLoadParameter.RenYuanLZB,
				spaceLoadParameter.XinFengLZB,
				spaceLoadParameter.QiTaLZB,
				spaceLoadParameter.WeiHuRZB,
				spaceLoadParameter.RenYuanRZB,
				spaceLoadParameter.XinFengRZB,
				spaceLoadParameter.LaoDongQD,
				spaceLoadParameter.ShiNeiZDFS,
				spaceLoadParameter.QiTaRZB,
				"'" + spaceLoadParameter.XinFengSJB + "'",
				"'" + spaceLoadParameter.RenYuanSJB + "'",
				"'" + spaceLoadParameter.ZhaoMingSJB + "'",
				"'" + spaceLoadParameter.DianDongSJB + "'",
				"'" + spaceLoadParameter.DianReSJB + "'",
				"'" + spaceLoadParameter.DianZiSJB + "'",
				spaceLoadParameter.DianDongGL,
				spaceLoadParameter.DianReGL,
				spaceLoadParameter.DianZiGL,
				spaceLoadParameter.RenYuanZS,
				spaceLoadParameter.YongShuiBZ,
				spaceLoadParameter.ZhaoDu,
				spaceLoadParameter.DianDongTSSYXS,
				spaceLoadParameter.DianReTSSYXS,
				spaceLoadParameter.DianZiTSSYXS,
				spaceLoadParameter.YunXuSJWDBD,
				spaceLoadParameter.YunXuDJSJWDBD,
				spaceLoadParameter.YunXuSJXDSDBD,
				spaceLoadParameter.YunXuDJSJXDSDBD,
				spaceLoadParameter.DongJiCNSNSJWD,
				spaceLoadParameter.DongJiCNSJXDSD,
				1,
				spaceLoadParameter.Id
			});
			return DataAccessOperate.Query(sqlStr);
		}

		private static SpaceLoadParameter TranformSpaceInfo(SpaceParameterInfo spi)
		{
			return new SpaceLoadParameter
			{
				DianDongGL = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电动设备功率(W/m2)")),
				DianDongSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "电动设备时间表")),
				DianDongTSSYXS = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电动设备同时使用系数")),
				DianReGL = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电热设备功率(W/m2)")),
				DianReSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "电热设备时间表")),
				DianReTSSYXS = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电热设备同时使用系数")),
				DianZiGL = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电子设备功率(W/m2)")),
				DianZiSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "电子设备时间表")),
				DianZiTSSYXS = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "电子设备同时使用系数")),
				DongJiCNSJXDSD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "冬季采暖设计相对湿度")),
				DongJiCNSNSJWD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "冬季采暖设计温度")),
				DongJiSNSJWD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "冬季空调设计温度")),
				DongJiSNSJXDSD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "冬季空调设计相对湿度")),
				LaoDongQD = Convert.ToInt32(SpaceParameterOperate.GetParam(spi, "劳动强度(enum)")),
				QiTaLZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "其他冷指标")),
				QiTaRZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "其他热指标(W/m^2)")),
				RenYuanMD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "人员密度")),
				RenYuanZS = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "人员总数")),
				RenYuanLZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "人员冷指标")),
				RenYuanRZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "人员热指标")),
				RenYuanSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "人员时间表")),
				SheBeiBZ = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "设备标准")),
				ShiNeiZDFS = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "室内允许最大风速(m/s)")),
				WeiHuLZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "维护冷指标")),
				WeiHuRZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "维护热指标")),
				XiaJiSNSJWD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "夏季空调设计温度")),
				XiaJiSNSJXDSD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "夏季空调设计相对湿度")),
				XinFengL = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "新风量")),
				XinFengLZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "新风冷指标")),
				XinFengRZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "新风热指标")),
				XinFengSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "新风时间表")),
				YongShuiBZ = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "用水量标准")),
				YunXuDJSJWDBD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "允许采暖设计温度波动")),
				YunXuDJSJXDSDBD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "允许采暖设计相对湿度波动")),
				YunXuSJWDBD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "允许设计温度波动")),
				YunXuSJXDSDBD = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "允许设计相对湿度波动")),
				ZaoYin = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "噪音")),
				ZhaoDu = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "照度")),
				ZhaoMingBZ = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "照明标准")),
				ZhaoMingSJB = Convert.ToString(SpaceParameterOperate.GetParam(spi, "照明时间表")),
				ZongLengZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "总冷指标")),
				ZongReZB = Convert.ToDouble(SpaceParameterOperate.GetParam(spi, "总热指标")),
				Id = Convert.ToInt32(SpaceParameterOperate.GetParam(spi, "ID")),
				RoomUseId = spi.RoomId,
				RoomUseName = spi.RoomName
			};
		}

		public static bool AddSpaceParameterInfo(SpaceParameterInfo spi)
		{
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("insert into RoomUse ([RTId],[Name],[Version]) values ({0},{1},{2})", spi.RoomTypeId, "'" + spi.RoomName + "'", 1);
			if (!DataAccessOperate.Query(sqlStr))
			{
				return false;
			}
			spi.RoomId = -1;
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			sqlStr = string.Format("select * from RoomUse where Name={0}", "'" + spi.RoomName + "'");
			DataTable dataTable = DataAccessOperate.GetDataTable(sqlStr);
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				spi.RoomId = Convert.ToInt32(dataRow["Id"]);
			}
			SpaceLoadParameter spaceLoadParameter = SpaceParameterOperate.TranformSpaceInfo(spi);
			string text = "insert into RULoadParam ([RUId],[DongJiSNSJWD],[DongJiSNSJXDSD],[XiaJiSNSJWD],[XiaJiSNSJXDSD],";
			text += "[RenYuanMD],[ZhaoMingBZ],[SheBeiBZ],[XinFengL],[ZaoYin],[ZongLengZB],[ZongReZB],[WeiHuLZB],[RenYuanLZB],[XinFengLZB],[QiTaLZB],[WeiHuRZB],";
			text += "[RenYuanRZB],[XinFengRZB],[LaoDongQD],[ShiNeiZDFS],[QiTaRZB],[XinFengSJB],[RenYuanSJB],[ZhaoMingSJB],[DianDongSJB],[DianReSJB],[DianZiSJB],";
			text += "[DianDongGL],[DianReGL],[DianZiGL],[RenYuanZS],[YongShuiBZ],[ZhaoDu],[DianDongTSSYXS],[DianReTSSYXS],[DianZiTSSYXS],[YunXuSJWDBD],[YunXuDJSJWDBD],";
			text += "[YunXuSJXDSDBD],[YunXuDJSJXDSDBD],[DongJiCNSNSJWD],[DongJiCNSJXDSD],[Version]) values ({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},";
			text += "{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37},";
			text += "{38},{39},{40},{41},{42},{43})";
			sqlStr = string.Format(text, new object[]
			{
				spaceLoadParameter.RoomUseId,
				spaceLoadParameter.DongJiSNSJWD,
				spaceLoadParameter.DongJiSNSJXDSD,
				spaceLoadParameter.XiaJiSNSJWD,
				spaceLoadParameter.XiaJiSNSJXDSD,
				spaceLoadParameter.RenYuanMD,
				spaceLoadParameter.ZhaoMingBZ,
				spaceLoadParameter.SheBeiBZ,
				spaceLoadParameter.XinFengL,
				spaceLoadParameter.ZaoYin,
				spaceLoadParameter.ZongLengZB,
				spaceLoadParameter.ZongReZB,
				spaceLoadParameter.WeiHuLZB,
				spaceLoadParameter.RenYuanLZB,
				spaceLoadParameter.XinFengLZB,
				spaceLoadParameter.QiTaLZB,
				spaceLoadParameter.WeiHuRZB,
				spaceLoadParameter.RenYuanRZB,
				spaceLoadParameter.XinFengRZB,
				spaceLoadParameter.LaoDongQD,
				spaceLoadParameter.ShiNeiZDFS,
				spaceLoadParameter.QiTaRZB,
				"'" + spaceLoadParameter.XinFengSJB + "'",
				"'" + spaceLoadParameter.RenYuanSJB + "'",
				"'" + spaceLoadParameter.ZhaoMingSJB + "'",
				"'" + spaceLoadParameter.DianDongSJB + "'",
				"'" + spaceLoadParameter.DianReSJB + "'",
				"'" + spaceLoadParameter.DianZiSJB + "'",
				spaceLoadParameter.DianDongGL,
				spaceLoadParameter.DianReGL,
				spaceLoadParameter.DianZiGL,
				spaceLoadParameter.RenYuanZS,
				spaceLoadParameter.YongShuiBZ,
				spaceLoadParameter.ZhaoDu,
				spaceLoadParameter.DianDongTSSYXS,
				spaceLoadParameter.DianReTSSYXS,
				spaceLoadParameter.DianZiTSSYXS,
				spaceLoadParameter.YunXuSJWDBD,
				spaceLoadParameter.YunXuDJSJWDBD,
				spaceLoadParameter.YunXuSJXDSDBD,
				spaceLoadParameter.YunXuDJSJXDSDBD,
				spaceLoadParameter.DongJiCNSNSJWD,
				spaceLoadParameter.DongJiCNSJXDSD,
				1
			});
			return DataAccessOperate.Query(sqlStr);
		}

		private static string GetParam(SpaceParameterInfo spi, string paraName)
		{
			string result = "";
			foreach (SpacePara spacePara in spi.Param)
			{
				if (spacePara.Key == paraName)
				{
					result = spacePara.Value;
				}
			}
			return result;
		}

		public static bool SetSpaceParaemeter(SpaceParameterInfo spi, Space space, IList<string> listPName)
		{
			bool result = false;
			foreach (string text in listPName)
			{
				Parameter parameter = space.GetParameter(text);
				if (parameter != null)
				{
					foreach (SpacePara spacePara in spi.Param)
					{
						if (!(spacePara.Key != text))
						{
							if (spacePara.Key.Contains("时间表"))
							{
								parameter.Set(spacePara.Value);
							}
							else if (spacePara.Key.Contains("湿度"))
							{
								parameter.Set(Convert.ToDouble(spacePara.Value) / 100.0);
							}
							else if (spacePara.Key.Contains("温度"))
							{
								parameter.Set(UnitConvert.CovertToAPI(Convert.ToDouble(spacePara.Value), (Autodesk.Revit.DB.DisplayUnitType)57));
							}
							else if (spacePara.Key.Equals("盈建科-劳动强度(enum)"))
							{
								int num = Convert.ToInt32(spacePara.Value);
								string text2 = "";
								switch (num)
								{
								case 0:
									text2 = "静坐";
									break;
								case 1:
									text2 = "极轻劳动";
									break;
								case 2:
									text2 = "轻度劳动";
									break;
								case 3:
									text2 = "中度劳动";
									break;
								case 4:
									text2 = "重度劳动";
									break;
								}
								parameter.Set(text2);
							}
							else
							{
								parameter.Set(Convert.ToDouble(spacePara.Value));
							}
						}
					}
				}
			}
			return result;
		}

		public static List<string> GetParameterName()
		{
			string uri = Product.InstallLocation + "\\Data\\负荷计算参数列表.xml";
			List<string> list = new List<string>();
			XElement xelement = XElement.Load(uri);
			foreach (XElement xelement2 in xelement.Elements())
			{
				list.Add(xelement2.Value);
			}
			return list;
		}

		public static int GetSpaceTypeNameByKey(string spaceName, List<RoomKeyToSpace> listRKTS)
		{
			int result = -1;
			foreach (RoomKeyToSpace roomKeyToSpace in listRKTS)
			{
				if (spaceName.Contains(roomKeyToSpace.RoomKey))
				{
					result = roomKeyToSpace.RoomUseId;
					break;
				}
			}
			return result;
		}

		public static int GetSpaceTypeNameByKey(List<RoomKeyToSpace> listRKTS, string spaceName)
		{
			int result = -1;
			IList<RoomKeyToSpace> list = new List<RoomKeyToSpace>();
			foreach (RoomKeyToSpace roomKeyToSpace in listRKTS)
			{
				string text = SpaceParameterOperate.info;
				SpaceParameterOperate.info = string.Concat(new string[]
				{
					text,
					"TKTS:",
					roomKeyToSpace.RoomKey,
					"  APN:",
					spaceName,
					"\n"
				});
				if (spaceName.Contains(roomKeyToSpace.RoomKey))
				{
					list.Add(roomKeyToSpace);
				}
			}
			if (list.Count > 0)
			{
				RoomKeyToSpace roomKeyToSpace2 = list[0];
				foreach (RoomKeyToSpace roomKeyToSpace3 in list)
				{
					if (roomKeyToSpace2 != null && StringTools.GetStringByteLength(roomKeyToSpace2.RoomKey) < StringTools.GetStringByteLength(roomKeyToSpace3.RoomKey))
					{
						roomKeyToSpace2 = roomKeyToSpace3;
					}
				}
				result = roomKeyToSpace2.RoomUseId;
			}
			return result;
		}

		public static List<RoomKeyToSpace> GetCreatSpaceToKey(List<RoomKeyToSpace> listRKTS)
		{
			List<RoomKeyToSpace> list = new List<RoomKeyToSpace>();
			foreach (RoomKeyToSpace roomKeyToSpace in listRKTS)
			{
				string[] array = roomKeyToSpace.RoomKey.Split(new char[]
				{
					'，',
					','
				});
				foreach (string roomKey in array)
				{
					list.Add(new RoomKeyToSpace
					{
						KeyId = roomKeyToSpace.KeyId,
						RoomUseId = roomKeyToSpace.RoomUseId,
						RoomUseName = roomKeyToSpace.RoomUseName,
						RoomKey = roomKey,
						Opetation = roomKeyToSpace.Opetation
					});
				}
			}
			list.Distinct<RoomKeyToSpace>();
			return list;
		}

		public static void ModifyGBXml(string path, IList<HYSpaceInfo> listHYSI, IList<Element> listZone)
		{
			XDocument xdocument = XDocument.Load(path);
			XNamespace ns = "http://www.gbxml.org/schema";
			XAttribute content = new XAttribute("HongyeData", "true");
			xdocument.Element(ns + "gbXML").Add(content);
			IList<string> list = new List<string>();
			IList<string> list2 = new List<string>();
			list2.Add("盈建科-人员时间表");
			list2.Add("盈建科-新风时间表");
			list2.Add("盈建科-照明时间表");
			list2.Add("盈建科-电动设备时间表");
			list2.Add("盈建科-电子设备时间表");
			list2.Add("盈建科-电热设备时间表");
			SpaceParameterOperate.m_TimeAssignList = SpaceParameterOperate.GetAllTimeInfo();
			XElement xelement = xdocument.Element(ns + "gbXML").Element(ns + "Campus").Element(ns + "Building");
			foreach (XElement xelement2 in xelement.Elements())
			{
				XElement xelement3 = xelement2.Element(ns + "CADObjectId");
				if (xelement3 != null)
				{
					foreach (HYSpaceInfo hyspaceInfo in listHYSI)
					{
						if (!(xelement3.Value != hyspaceInfo.Id))
						{
							xelement2.Add(new XElement(ns + "HongyeDataItem"));
							XElement xelement4 = xelement2.Element(ns + "HongyeDataItem");
							IEnumerator<SpacePara> enumerator3 = hyspaceInfo.Param.GetEnumerator();
							{
								while (enumerator3.MoveNext())
								{
									SpacePara spacePara = enumerator3.Current;
									if (spacePara.Key.Contains('('))
									{
										spacePara.Key = spacePara.Key.Substring(0, spacePara.Key.IndexOf("("));
									}
									XAttribute content2 = new XAttribute(spacePara.Key, spacePara.Value);
									xelement4.Add(content2);
									if (list2.Contains(spacePara.Key) && !list.Contains(spacePara.Value))
									{
										list.Add(spacePara.Value);
									}
								}
								break;
							}
						}
					}
				}
			}
			SpaceParameterOperate.AddHongyeDataItemEx(xdocument, list);
			SpaceParameterOperate.SetZoneHumPara(xdocument, listZone);
			xdocument.Save(path);
		}

		private static void SetZoneHumPara(XDocument xDoc, IList<Element> listZone)
		{
			XNamespace ns = "http://www.gbxml.org/schema";
			XElement xelement = xDoc.Element(ns + "gbXML");
			IEnumerable<XElement> enumerable = xelement.Elements(ns + "Zone");
			foreach (XElement xelement2 in enumerable)
			{
				if (xelement2 != null)
				{
					XElement xelement3 = xelement2.Element(ns + "CADObjectId");
					if (xelement3 != null)
					{
						foreach (Element element in listZone)
						{
							Zone zone = element as Zone;
							if (zone.Id.ToString() == xelement3.Value)
							{
								if (xelement2.Element(ns + "OAFlowPerPerson") == null)
								{
									XElement xelement4 = new XElement(ns + "OAFlowPerPerson");
                                    xelement4.Value = UnitConvert.CovertFromAPI((DisplayUnitType)64, zone.GetYJKOutDoorAirPerPerson()).ToString();
									XAttribute content = new XAttribute("unit", "LPerSec");
									xelement4.Add(content);
									xelement2.Add(xelement4);
								}
                                string content2 = StringTools.DoubleToString(UnitConvert.CovertFromAPI((DisplayUnitType)19, zone.HumidificationSetPoint), 0);
                                string content3 = StringTools.DoubleToString(UnitConvert.CovertFromAPI((DisplayUnitType)19, zone.DehumidificationSetPoint), 0);
								XElement xelement5 = new XElement(ns + "DesignHeatH", content2);
								XElement xelement6 = new XElement(ns + "DesignCoolH", content3);
								XAttribute content4 = new XAttribute("unit", "%");
								xelement6.Add(content4);
								xelement5.Add(content4);
								xelement2.Add(new object[]
								{
									xelement5,
									xelement6
								});
							}
						}
					}
				}
			}
		}

		private static void AddHongyeDataItemEx(XDocument xDoc, IList<string> lstTimeAssign)
		{
			XNamespace ns = "http://www.gbxml.org/schema";
			XElement xelement = xDoc.Element(ns + "gbXML");
			foreach (TimeAssign timeAssign in SpaceParameterOperate.m_TimeAssignList)
			{
				if (timeAssign != null && lstTimeAssign.Contains(timeAssign.TsName))
				{
					xelement.Add(new XElement(ns + "DaySchedule"));
					IEnumerable<XElement> enumerable = xelement.Elements(ns + "DaySchedule");
					foreach (XElement xelement2 in enumerable)
					{
						if (!xelement2.HasAttributes)
						{
							XAttribute content = new XAttribute("id", timeAssign.TsName);
							xelement2.Add(content);
							new XElement(ns + "ScheduleValue");
							xelement2.Add(new object[]
							{
								new XElement(ns + "ScheduleValue", timeAssign.T0),
								new XElement(ns + "ScheduleValue", timeAssign.T1),
								new XElement(ns + "ScheduleValue", timeAssign.T2),
								new XElement(ns + "ScheduleValue", timeAssign.T3),
								new XElement(ns + "ScheduleValue", timeAssign.T4),
								new XElement(ns + "ScheduleValue", timeAssign.T5),
								new XElement(ns + "ScheduleValue", timeAssign.T6),
								new XElement(ns + "ScheduleValue", timeAssign.T7),
								new XElement(ns + "ScheduleValue", timeAssign.T8),
								new XElement(ns + "ScheduleValue", timeAssign.T9),
								new XElement(ns + "ScheduleValue", timeAssign.T10),
								new XElement(ns + "ScheduleValue", timeAssign.T11),
								new XElement(ns + "ScheduleValue", timeAssign.T12),
								new XElement(ns + "ScheduleValue", timeAssign.T13),
								new XElement(ns + "ScheduleValue", timeAssign.T14),
								new XElement(ns + "ScheduleValue", timeAssign.T15),
								new XElement(ns + "ScheduleValue", timeAssign.T16),
								new XElement(ns + "ScheduleValue", timeAssign.T17),
								new XElement(ns + "ScheduleValue", timeAssign.T18),
								new XElement(ns + "ScheduleValue", timeAssign.T19),
								new XElement(ns + "ScheduleValue", timeAssign.T20),
								new XElement(ns + "ScheduleValue", timeAssign.T21),
								new XElement(ns + "ScheduleValue", timeAssign.T22),
								new XElement(ns + "ScheduleValue", timeAssign.T23)
							});
						}
					}
				}
			}
		}

		private static IList<TimeAssign> GetAllTimeInfo()
		{
			XmlDocument xmlDocument = new XmlDocument();
			string sourceFileName = Product.InstallLocation + "\\Data\\HYSpaceInfo.xml";
			if (!File.Exists(SpaceParameterOperate.m_strHYSpaceInfo))
			{
				File.Copy(sourceFileName, SpaceParameterOperate.m_strHYSpaceInfo);
			}
			if (File.Exists(SpaceParameterOperate.m_strHYSpaceInfo))
			{
				xmlDocument.Load(SpaceParameterOperate.m_strHYSpaceInfo);
			}
			IList<TimeAssign> list = new List<TimeAssign>();
			try
			{
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceInfo");
				XmlNode xmlNode2 = xmlNode.SelectSingleNode("SpaceTime");
				List<XmlElement> list2 = new List<XmlElement>();
				foreach (object obj in xmlNode2.ChildNodes)
				{
					list2.Add(obj as XmlElement);
				}
				foreach (XmlElement xmlElement in list2)
				{
					list.Add(new TimeAssign
					{
						Operation = "无操作",
						TsName = (string.IsNullOrEmpty(xmlElement.GetAttribute("Name")) ? "" : xmlElement.GetAttribute("Name")),
						TsParent = (string.IsNullOrEmpty(xmlElement.GetAttribute("Type")) ? "" : xmlElement.GetAttribute("Type")),
						Id = (string.IsNullOrEmpty(xmlElement.GetAttribute("Id")) ? 0 : Convert.ToInt32(xmlElement.GetAttribute("Id"))),
						Version = 1,
						T0 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T0")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T0"))),
						T1 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T1")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T1"))),
						T2 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T2")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T2"))),
						T3 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T3")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T3"))),
						T4 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T4")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T4"))),
						T5 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T5")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T5"))),
						T6 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T6")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T6"))),
						T7 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T7")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T7"))),
						T8 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T8")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T8"))),
						T9 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T9")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T9"))),
						T10 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T10")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T10"))),
						T11 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T11")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T11"))),
						T12 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T12")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T12"))),
						T13 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T13")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T13"))),
						T14 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T14")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T14"))),
						T15 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T15")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T15"))),
						T16 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T16")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T16"))),
						T17 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T17")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T17"))),
						T18 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T18")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T18"))),
						T19 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T19")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T19"))),
						T20 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T20")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T20"))),
						T21 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T21")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T21"))),
						T22 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T22")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T22"))),
						T23 = (string.IsNullOrEmpty(xmlElement.GetAttribute("T23")) ? 0.0 : Convert.ToDouble(xmlElement.GetAttribute("T23")))
					});
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
			return list;
		}

		public static IList<HYSpaceInfo> GetAllHYSpaceInfo(Document doc)
		{
			IList<HYSpaceInfo> list = new List<HYSpaceInfo>();
			IList<string> parameterName = SpaceParameterOperate.GetParameterName();
			IList<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_MEPSpaces);
			IList<Space> list2 = new List<Space>();
			foreach (Element element in elementByCategory)
			{
				list2.Add(element as Space);
			}
			return SpaceParameterOperate.InitialSpaceInfo(parameterName, list2);
		}

		private static IList<HYSpaceInfo> InitialSpaceInfo(IList<string> listPara, IList<Space> listSpace)
		{
			IList<HYSpaceInfo> list = new List<HYSpaceInfo>();
			foreach (Space space in listSpace)
			{
				Zone zone = space.Zone;
				HYSpaceInfo hyspaceInfo = new HYSpaceInfo();
				hyspaceInfo.Id = space.Id.ToString();
				hyspaceInfo.Name = space.Name;
				hyspaceInfo.Param = new List<SpacePara>();
				foreach (string text in listPara)
				{
					if (!YJKRevitTools.ShareParaBeExist(space, text))
					{
						return null;
					}
					SpacePara spacePara = new SpacePara();
					Parameter parameter = space.GetParameter(text);
					if (parameter.HasValue)
					{
						if (text == "劳动强度(enum)" || text.Contains("时间表"))
						{
							spacePara.Value = parameter.AsString();
						}
						else
						{
							spacePara.Value = parameter.AsDouble().ToString();
						}
						spacePara.Key = text;
						hyspaceInfo.Param.Add(spacePara);
					}
				}
				list.Add(hyspaceInfo);
			}
			return list;
		}

		public static void SetSpaceParaValue(SpaceParameterInfo spi, Space space)
		{
            double num = UnitConvert.CovertFromAPI((DisplayUnitType)12, space.Area);
			foreach (SpacePara spacePara in spi.Param)
			{
				string key;
				if ((key = spacePara.Key) != null)
				{
					if (!(key == "盈建科-总冷指标(W/m^2)"))
					{
						if (!(key == "盈建科-总热指标(W/m^2)"))
						{
							if (key == "盈建科-人员密度(人/m^2)")
							{
                                space.OccupancyUnit = (OccupancyUnit)1;
								double num2 = 1.0 / Convert.ToDouble(spacePara.Value);
								if (num2 > 0.135 && num2 < 929.03)
								{
									space.AreaperPerson = UnitConvert.CovertToAPI(Convert.ToDouble(num2), (Autodesk.Revit.DB.DisplayUnitType)12);
								}
							}
						}
						else
						{
							Parameter parameter = space.GetParameter(BuiltInParameter.ROOM_DESIGN_HEATING_LOAD_PARAM);
							double value = Convert.ToDouble(spacePara.Value);
							double num3 = UnitConvert.CovertToAPI(value, (Autodesk.Revit.DB.DisplayUnitType)40);
							parameter.Set(num3 * num / 1000.0);
						}
					}
					else
					{
						Parameter parameter = space.GetParameter(BuiltInParameter.ROOM_DESIGN_COOLING_LOAD_PARAM);
						double value2 = Convert.ToDouble(spacePara.Value);
						double num4 = UnitConvert.CovertToAPI(value2, (Autodesk.Revit.DB.DisplayUnitType)40);
						parameter.Set(num4 * num / 1000.0);
					}
				}
			}
		}

		public static Dictionary<Zone, int> CreatZoneSetPara(Document doc, List<RoomKeyToSpace> listKey, IList<SpaceParameterInfo> listSPI)
		{
			Dictionary<Zone, int> dictionary = new Dictionary<Zone, int>();
			IEnumerable<int> enumerable = (from key in listKey
			select key.RoomUseId).Distinct<int>();
			IEnumerator<int> enumerator = enumerable.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					int item = enumerator.Current;
					Zone zone = SpaceParameterOperate.CreatHYZone(doc);
					IEnumerable<SpaceParameterInfo> source = from space in listSPI
					where space.RoomId == item
					select space;
					zone.Name = source.First<SpaceParameterInfo>().RoomName;
					if (source.Count<SpaceParameterInfo>() > 0)
					{
						SpaceParameterOperate.SetZonePara(doc, zone, source.First<SpaceParameterInfo>());
						dictionary.Add(zone, item);
					}
				}
			}
			return dictionary;
		}

		public static Zone CreatZoneSetParaBySpace(Document doc, string Zonename, SpaceParameterInfo spaceInfo)
		{
			Zone zone = SpaceParameterOperate.CreatHYZone(doc);
			zone.Name = Zonename;
			SpaceParameterOperate.SetZonePara(doc, zone, spaceInfo);
			return zone;
		}

		public static Zone CreatHYZone(Document doc)
		{
			Zone result;
			try
			{
				List<Element> elementByCategory = YJKElementFilter.GetElementByCategory(doc, BuiltInCategory.OST_Levels);
				Level level = null;
				foreach (Element element in elementByCategory)
				{
					level = (element as Level);
					if (level != null)
					{
						break;
					}
				}
				Parameter parameter = doc.ActiveView.GetParameter(BuiltInParameter.VIEW_PHASE);
				ElementId elementId = parameter.AsElementId();
				Phase phase = doc.GetElement(elementId) as Phase;
				Zone zone = doc.Create.NewZone(level, phase);
				result = zone;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static void SetZonePara(Document doc, Zone zone, SpaceParameterInfo spi)
		{
			foreach (SpacePara spacePara in spi.Param)
			{
				string key;
				if ((key = spacePara.Key) != null)
				{
					if (!(key == "盈建科-夏季空调设计温度(℃)"))
					{
						if (!(key == "盈建科-冬季空调设计温度(℃)"))
						{
							if (!(key == "盈建科-夏季空调设计相对湿度(%)"))
							{
								if (!(key == "盈建科-冬季空调设计相对湿度(%)"))
								{
									if (!(key == "盈建科-新风量(m^3/(h.人))"))
									{
									}
								}
								else
								{
									zone.HumidificationSetPoint = UnitConvert.CovertToAPI(Convert.ToDouble(spacePara.Value), (Autodesk.Revit.DB.DisplayUnitType)19);
								}
							}
							else
							{
								zone.DehumidificationSetPoint = UnitConvert.CovertToAPI(Convert.ToDouble(spacePara.Value), (Autodesk.Revit.DB.DisplayUnitType)19);
							}
						}
						else
						{
							zone.HeatingSetPoint = UnitConvert.CovertToAPI(Convert.ToDouble(spacePara.Value), (Autodesk.Revit.DB.DisplayUnitType)57);
						}
					}
					else
					{
						zone.CoolingSetPoint = UnitConvert.CovertToAPI(Convert.ToDouble(spacePara.Value), (Autodesk.Revit.DB.DisplayUnitType)57);
					}
				}
			}
		}

		public static IList<RoomType> GetAllRoomType()
		{
			IList<RoomType> list = new List<RoomType>();
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("select * from RoomType", new object[0]);
			DataTable dataTable = DataAccessOperate.GetDataTable(sqlStr);
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new RoomType
				{
					RoomTypeId = Convert.ToInt32(dataRow["Id"]),
					RoomTypeName = Convert.ToString(dataRow["Name"])
				});
			}
			return list;
		}

		public static IList<RoomUse> GetAllRoomUse()
		{
			IList<RoomUse> list = new List<RoomUse>();
			DataAccessOperate.SetDataSource(SpaceParameterOperate.dataSource);
			string sqlStr = string.Format("select * from RoomUse", new object[0]);
			DataTable dataTable = DataAccessOperate.GetDataTable(sqlStr);
			foreach (object obj in dataTable.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				list.Add(new RoomUse
				{
					RoomTypeId = Convert.ToInt32(dataRow["RTId"]),
					RoomName = Convert.ToString(dataRow["Name"]),
					RoomUseId = Convert.ToInt32(dataRow["Id"])
				});
			}
			return list;
		}

		public static List<RoomKeyToSpace> GetAllRoomKeyInfo()
		{
			List<RoomKeyToSpace> list = new List<RoomKeyToSpace>();
			IList<RoomUse> allRoomUse = SpaceParameterOperate.GetAllRoomUse();
			try
			{
				XmlDocument xmlDocument = XMLOperating.LoadXml(SpaceParameterOperate.pathSpaceKey);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceKeywords");
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					RoomKeyToSpace roomKeyToSpace = new RoomKeyToSpace();
					XmlElement xmlElement = xmlNode2 as XmlElement;
					roomKeyToSpace.KeyId = xmlElement.GetAttribute("KID");
					roomKeyToSpace.RoomKey = xmlElement.GetAttribute("RoomKey");
					roomKeyToSpace.RoomUseId = Convert.ToInt32(xmlElement.GetAttribute("RoomUseId"));
					RoomUse roomUse = SpaceParameterOperate.BeExsitRoomUse(roomKeyToSpace.RoomUseId, allRoomUse);
					if (roomUse == null)
					{
						roomKeyToSpace.RoomUseName = xmlElement.GetAttribute("RoomUseName");
					}
					else
					{
						roomKeyToSpace.RoomUseId = roomUse.RoomUseId;
						roomKeyToSpace.RoomUseName = roomUse.RoomTypeName + "-" + roomUse.RoomName;
					}
					roomKeyToSpace.Opetation = xmlElement.GetAttribute("Operation");
					list.Add(roomKeyToSpace);
				}
			}
			catch (Exception)
			{
				throw;
			}
			return list;
		}

		public static List<RoomKeyToSpace> GetAllRoomKeyInfo(IList<RoomUse> listRoom)
		{
			List<RoomKeyToSpace> list = new List<RoomKeyToSpace>();
			try
			{
				XmlDocument xmlDocument = XMLOperating.LoadXml(SpaceParameterOperate.pathSpaceKey);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceKeywords");
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					RoomKeyToSpace roomKeyToSpace = new RoomKeyToSpace();
					XmlElement xmlElement = xmlNode2 as XmlElement;
					roomKeyToSpace.KeyId = xmlElement.GetAttribute("KID");
					roomKeyToSpace.RoomKey = xmlElement.GetAttribute("RoomKey");
					roomKeyToSpace.RoomUseId = Convert.ToInt32(xmlElement.GetAttribute("RoomUseId"));
					RoomUse roomUse = SpaceParameterOperate.BeExsitRoomUse(roomKeyToSpace.RoomUseId, listRoom);
					if (roomUse == null)
					{
						roomKeyToSpace.RoomUseName = xmlElement.GetAttribute("RoomUseName");
					}
					else
					{
						roomKeyToSpace.RoomUseId = roomUse.RoomUseId;
						roomKeyToSpace.RoomUseName = roomUse.RoomTypeName + "-" + roomUse.RoomName;
					}
					roomKeyToSpace.Opetation = xmlElement.GetAttribute("Operation");
					list.Add(roomKeyToSpace);
				}
			}
			catch (Exception)
			{
				throw;
			}
			return list;
		}

		private static RoomUse BeExsitRoomUse(int roomId, IList<RoomUse> listRoom)
		{
			bool flag = false;
			foreach (RoomUse roomUse in listRoom)
			{
				if (roomUse.RoomUseId == roomId)
				{
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				return listRoom[0];
			}
			return null;
		}

		public static bool DeleteRoomKeyInfo(string keyId)
		{
			bool result = false;
			try
			{
				XmlDocument xmlDocument = XMLOperating.LoadXml(SpaceParameterOperate.pathSpaceKey);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceKeywords");
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					XmlElement xmlElement = xmlNode2 as XmlElement;
					if (xmlElement.GetAttribute("KID") == keyId)
					{
						xmlNode.RemoveChild(xmlNode2);
					}
				}
				xmlDocument.Save(SpaceParameterOperate.pathSpaceKey);
				result = true;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static bool AddRoomKeyInfo(RoomKeyToSpace rkts)
		{
			bool result = false;
			try
			{
				XmlDocument xmlDocument = XMLOperating.LoadXml(SpaceParameterOperate.pathSpaceKey);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceKeywords");
				XmlElement xmlElement = xmlDocument.CreateElement("SpaceKeyword");
				xmlElement.SetAttribute("KID", rkts.KeyId);
				xmlElement.SetAttribute("RoomUseName", rkts.RoomUseName);
				xmlElement.SetAttribute("RoomUseId", rkts.RoomUseId.ToString());
				xmlElement.SetAttribute("RoomKey", rkts.RoomKey);
				xmlElement.SetAttribute("Operation", rkts.Opetation);
				xmlNode.AppendChild(xmlElement);
				xmlDocument.Save(SpaceParameterOperate.pathSpaceKey);
				result = true;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		public static bool UpdataRoomKeyInfo(RoomKeyToSpace rkts)
		{
			bool result = false;
			try
			{
				XmlDocument xmlDocument = XMLOperating.LoadXml(SpaceParameterOperate.pathSpaceKey);
				XmlNode xmlNode = xmlDocument.SelectSingleNode("SpaceKeywords");
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					XmlElement xmlElement = xmlNode2 as XmlElement;
					if (xmlElement.GetAttribute("KID") == rkts.KeyId)
					{
						xmlElement.SetAttribute("RoomUseName", rkts.RoomUseName);
						xmlElement.SetAttribute("RoomUseId", rkts.RoomUseId.ToString());
						xmlElement.SetAttribute("RoomKey", rkts.RoomKey);
						xmlElement.SetAttribute("Operation", rkts.Opetation);
					}
				}
				xmlDocument.Save(SpaceParameterOperate.pathSpaceKey);
				result = true;
			}
			catch (Exception)
			{
				throw;
			}
			return result;
		}

		private static string dataSource = Product.InstallLocation + "\\Data\\LoadParam.mdb";

		private static string pathSpaceKey = Product.InstallLocation + "\\Data\\RoomToSpaceKey.xml";

		private static string spaceShareParaPath = Product.InstallLocation + "\\Data\\WallData.txt";

		private static string spaceLoadPath = Product.InstallLocation + "\\Data\\负荷计算参数列表.xml";

		private static string loadShareParaPath = Product.InstallLocation + "\\Data\\SpaceData.txt";

		private static string m_strHYSpaceInfo = Product.UserDataLocation + "\\HYSpaceInfo.xml";

		private static IList<TimeAssign> m_TimeAssignList = null;

		public static string info = "";
	}
}
